﻿<UserControl x:Class="MemoryGames.Games.Memory.Card3D"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:MemoryGames" 
    Height="300" Width="300" MouseUp="UserControl_MouseUp">
	<UserControl.Resources>
		<DiffuseMaterial x:Key="CubeSideMaterial" Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
		<LinearGradientBrush x:Key="BlackBackground" EndPoint="1,1" StartPoint="0.25,0.25">
			<GradientStop Color="#FF000000" Offset="0.325"/>
			<GradientStop Color="#FFFFFFFF" Offset="1"/>
		</LinearGradientBrush>
		<LinearGradientBrush x:Key="GreenBackground" EndPoint="0.5,1" StartPoint="0.5,0">
			<GradientStop Color="#FFFFFFFF" Offset="0"/>
			<GradientStop Color="#FF176204" Offset="0.74"/>
		</LinearGradientBrush>
        <Storyboard x:Key="SbRotateCardFront" TargetName="RotateCardFront" TargetProperty="Angle">
            <DoubleAnimation From="0" To="180" Duration="0:0:1" IsAdditive="True" />
        </Storyboard>
        <Storyboard x:Key="SbRotateCardBack" TargetName="RotateCardBack" TargetProperty="Angle">
            <DoubleAnimation From="0" To="180" Duration="0:0:1" IsAdditive="True" />
        </Storyboard>
    </UserControl.Resources>
	<Grid x:Name="MainGrid">
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*" />
		</Grid.ColumnDefinitions>
		<Grid.RowDefinitions>
			<RowDefinition Height="*" />
		</Grid.RowDefinitions>
		<Viewport3D Grid.Row="0" Grid.Column="0" x:Name="CubeV3D" ClipToBounds="False" RenderOptions.BitmapScalingMode="LowQuality">
			<Viewport3D.Camera>
				<OrthographicCamera Position="0,0,1" LookDirection="0,0,-1" Width="2">
					<OrthographicCamera.Transform>
						<RotateTransform3D>
							<RotateTransform3D.Rotation>
								<QuaternionRotation3D Quaternion="0, 0, 0, 0" x:Name="CameraRotation"/>
							</RotateTransform3D.Rotation>
						</RotateTransform3D>
					</OrthographicCamera.Transform>
				</OrthographicCamera>
			</Viewport3D.Camera>

            <!-- Card Front Side -->
			<Viewport2DVisual3D Material="{StaticResource CubeSideMaterial}">

				<Viewport2DVisual3D.Geometry>
					<MeshGeometry3D Positions="-1,1,0  -1,-1,0  1,-1,0  1,1,0"
                                    TextureCoordinates="0,0  0,1  1,1  1,0" 
                                    TriangleIndices="0 1 2  0 2 3"/>
				</Viewport2DVisual3D.Geometry>

				<Viewport2DVisual3D.Transform>
					<Transform3DGroup>
						<RotateTransform3D>
							<RotateTransform3D.Rotation>
								<AxisAngleRotation3D x:Name="RotateCardFront" Axis="1,1,0" Angle="180" />
							</RotateTransform3D.Rotation>
						</RotateTransform3D>
					</Transform3DGroup>
				</Viewport2DVisual3D.Transform>

				<!-- Grid to hold 2D content -->
				<Grid x:Name="CardFrontSidePanel">
					<Rectangle Fill="Black"></Rectangle>
					<Image Name="CardImageFront" Margin="5" Stretch="Fill">
					</Image>
				</Grid>

			</Viewport2DVisual3D>

			<!-- Card Back Side -->
			<Viewport2DVisual3D Material="{StaticResource CubeSideMaterial}">

				<Viewport2DVisual3D.Geometry>
					<MeshGeometry3D Positions="1,1,0  1,-1,0  -1,-1,0  -1,1,0"
                                    TextureCoordinates="1,0 0,0 0,1 1,1" 
                                    TriangleIndices="0 1 2  0 2 3"/>
				</Viewport2DVisual3D.Geometry>

				<Viewport2DVisual3D.Transform>
					<Transform3DGroup>
						<RotateTransform3D>
							<RotateTransform3D.Rotation>
								<AxisAngleRotation3D x:Name="RotateCardBack" Axis="1,1,0" Angle="180" />
							</RotateTransform3D.Rotation>
						</RotateTransform3D>
					</Transform3DGroup>
				</Viewport2DVisual3D.Transform>

				<!-- Grid to hold 2D content -->
				<Grid x:Name="CardBackSidePanel">
					<Rectangle>
						<Rectangle.Fill>
							<SolidColorBrush Color="Black"/>
						</Rectangle.Fill>
					</Rectangle>
					<Image Name="CardImageBack" Margin="5" Stretch="Fill" Source="Resources/memory_card_back.png">
					</Image>
				</Grid>

			</Viewport2DVisual3D>

			<!-- Lights -->
			<ModelVisual3D>
				<ModelVisual3D.Content>
					<AmbientLight Color="#FFFFFFFF" />
				</ModelVisual3D.Content>
			</ModelVisual3D>
		</Viewport3D>
    </Grid>
</UserControl>
